package com.lagou.bean;

import com.lagou.service.HomeWorkService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

@Component
public class ConsumerComponent {

    private static final Logger log = LoggerFactory.getLogger(ConsumerComponent.class);

    @Reference
    private HomeWorkService homeWorkService;

    public void monitor() throws InterruptedException {

        // 创建线程池
        ExecutorService executorService = new ThreadPoolExecutor(20, 30, 3000,
                TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<>(50),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

        for (int i = 0; i < 2000; i++) {
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    homeWorkService.methodA();
                }
            });
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    homeWorkService.methodB();
                }
            });
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    homeWorkService.methodC();
                }
            });
            Thread.sleep(30);
        }

    }

}
